﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using cbmobile.DAC;
using cbmobile.BLC;


namespace cbmobile
{
    public partial class Login : System.Web.UI.Page
    {
        SqlConnection cnn = null;
        DBConnection dbCn = new DBConnection("PQT");
        private CBMobileEntities da = null;
        protected Login()
        {
            da = new CBMobileEntities();
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected Member DangNhap(string TenDangNhap, string MatKhau)
        {
            IList<Member> list = da.Members.Where(z => z.TenDangNhap == TenDangNhap).Where(p=>p.MatKhau==MatKhau).ToList();
            if (list.Count == 0)
                return null;
            return list.First();
        }



        protected void Check()
        {
            string TenDangNhap = Login1.UserName;
            string MatKhau = Login1.Password;
            Member dt = DangNhap(TenDangNhap, MatKhau);
            if (dt != null)
            {
                if (dt.TrangThai == 1 && dt.Role_Member == 1)
                {
                    
                    Session["ID"] = dt.UserID.ToString();
                    Session["User"] = dt.TenDangNhap.ToString();
                    Response.Redirect("/RenderMain.aspx?muid=TinTuc_List");
                }
            }
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            Check();
        }
    }
}